<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>尤迈桃李会</title>
    <script src="js/rem.js"></script>
    <link rel="stylesheet" href="css/weui.min.css">
    <link rel="stylesheet" href="css/jquery-weui.min.css">
    <link rel="stylesheet" href="css/public.css">
    <link rel="stylesheet" href="css/index.css">
    <script>(function() {var _53code = document.createElement("script");_53code.src = "https://tb.53kf.com/code/code/96d8f960b261e49515450f8953b044bc5/1";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_53code, s);})();</script>
</head>
<body>
    <div class="login-wrapper plr15">
        <div class="btn-wrapper">
            <a class="btn" href="register.html">注册</a>
        </div>
        <div class="tit">账号密码登录</div>
        <form action="#" onsubmit="login();return false;" method="post" id="loginForm" autocomplete="off">
            <ul class="list">
                <li><input class="input" name="loginMobile" type="text" placeholder="请输入手机号码"></li>
                <li><input class="input" name="password" type="password" placeholder="请输入密码"></li>
            </ul>
            <div class="other-btns flex-btw">
                <a class="code-login-btn" href="login-code.html">手机验证码登录</a>
                <a class="forget-pass-btn" href="login-pass-forget.html">忘记密码？</a>
            </div>
            <input class="pub-submit-btn" type="submit" value="立即登录">
            <div class="agreement">
                登录即同意尤迈桃李会
                <a href="#">用户协议</a>和<a href="#">隐私政策</a>
            </div>
        </form>
        <div class="three-login plr15">
            <p class="tit"><span>第三方登录</span></p>
            <a href="javascript:;" id="wechatBtn"></a>
        </div>
    </div>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/jquery-weui.min.js"></script>
    <script src="js/md5.js"></script>
    <script src="js/public.js"></script>
    <script>
        // 微信一键注册
        var code = getQueryString('code');
        if(code){
            getOpenid();
        }else {
            $('#wechatBtn').click(function(){
                getWxopenid();
            })
        }

        // 手机号登录
        var loginState = false;
        function login(){
            var option = $('#loginForm').serializeObject();

            // 数据验证
            if(validEmpty(option.loginMobile, '手机号不能为空')) return;
            if(validEmpty(option.password, '密码不能为空')) return;
            if(validPhone(option.loginMobile)) return;
            option.password = md5(option.password);
            option.loginType = '1';
            loginState = true;
            http('/user/login', {
                loading: true,
                hasToken: false,
                data: option,
                success: function(res){
                    if(res.code === '01'){
                        toast('登录成功');
                        setCookie('token', res.data.token);
                        setCookie('userId', res.data.userId, 1);
                        localStorage.setItem("mobile", option.loginMobile);
                        backIndex(1000);
                    }
                },
                complete: function(){
                    loginState = false;
                }
            })
        }
    </script>
</body>
</html>